import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DeviceRepositoryModule } from '@app/db/device-repository/device-repository.module';
import { DeviceSecretRepositoryModule } from '@app/db/device-secret-repository/device-secret-repository.module';
import { HttpModule } from '@nestjs/axios';
import { CacheModule } from '@app/cache';

@Module({
    imports : [
        HttpModule,
        ConfigureModule.forRoot(),
        CacheModule,
		TypeOrmModule.forRootAsync({
			imports : [ConfigureModule],
			inject : [ConfigureService],
			useFactory : (config:ConfigureService) => {
				return {
					type: config.get('DB_TYPE'),
					host: config.get('DB_HOST'),
					port: Number(config.get('DB_PORT')),
					database: config.get('DB_NAME'),
					username: config.get('DB_USERNAME'),
					password: config.get('DB_PASSWORD'),
					synchronize: JSON.parse(config.get('DB_SYNCHRONIZE')),
					autoLoadEntities : JSON.parse(config.get('DB_AUTOLOADENTITIES')),
					poolSize : Number(config.get('DB_POOLSIZE'))
				}
			}
		}),

        DeviceRepositoryModule,
        DeviceSecretRepositoryModule,
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}
